[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 access()                Check File Permission Setting

 #include   <io.h>

 int        access(pathname,mode);
 const char *pathname;                   Name of file or directory
 int        mode;                        Permission setting

    access() checks the file or directory specified by `pathname'.  It
    uses the values specified in 'mode' to determine whether the file
    exists and, if a file, whether it can be read or written to.  'mode'
    can have any of the following values:

                Value       Checks For
                 00      Existence only
                 02      Write permission
                 04      Read permission
                 06      Read and write permission

       Returns:     0 if the file has the permission specified by 'mode'
                    and -1 if the file does not exist or its read/write
                    access does not match 'mode'.  If an error occurs,
                    'errno' is set to:

                    EACCES    Access denied; file's permission does
                              not allow the specified access
                    ENOENT    File or pathname not found

         Notes:     In the MS-DOS environment, all files have read
                    access, so this function is used to determine whether
                    a file exists or can be written to. Likewise, because
                    all directories have both read and write access, this
                    function simply finds out if a directory exists.

   -------------------------------- Example ---------------------------------

    The following statements check for write permission and print an
    error message.

           #include <io.h>
           #include <stdlib.h>                /* For perror */

           main()
           {
               if ((access("inventory.dta",2)) == -1)
                   perror("cannot write to inventory file");
           }


See Also: chmod() fstat() open() stat()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson